package net.tv90.bfmccore.slot;

import java.util.HashMap;
import java.util.Map;

public class Slot {

    //成员变量
    //主武器,包含物品id，弹药id，弹药数量，配件列表
    public MainWeapon mainWeapon;

    //副武器,包含物品id，弹药id，弹药数量，配件列表
    public SideArms sidearms;

    //近战武器,包含物品id
    public String meleeWeapon;

    //服装,包含id
    public String cloth;

    //投掷物，包含id和数量
    public Grenade grenade;

    //道具，包含id,数量和物品栏位置索引
    public HashMap<String, HashMap<Integer, Integer>> gadgets;

    public HashMap<String, HashMap<Integer, Integer>> gadgets2;

    public Slot() {
    }

    public Slot(MainWeapon mainWeapon, SideArms sideArms, String meleeWeapon, String cloth,
                Grenade grenade, HashMap<String, HashMap<Integer, Integer>> gadgets) {
        this.mainWeapon = mainWeapon;
        this.sidearms = sideArms;
        this.meleeWeapon = meleeWeapon;
        this.cloth = cloth;
        this.grenade = grenade;
        this.gadgets = gadgets;
    }

    public Slot(MainWeapon mainWeapon, SideArms sideArms, String meleeWeapon, String cloth,
                Grenade grenade, HashMap<String, HashMap<Integer, Integer>> gadgets, HashMap<String, HashMap<Integer, Integer>> gadgets2) {
        this.mainWeapon = mainWeapon;
        this.sidearms = sideArms;
        this.meleeWeapon = meleeWeapon;
        this.cloth = cloth;
        this.grenade = grenade;
        this.gadgets = gadgets;
        this.gadgets2 = gadgets2;
    }

    //反序列化构造器
    public Slot(HashMap<Object, Object> map) {
        this.mainWeapon = new MainWeapon((HashMap<Object, Object>) map.get("MainWeapon"));
        this.sidearms = new SideArms((HashMap<Object, Object>) map.get("SideArms"));
        this.meleeWeapon = String.valueOf(map.get("MeleeWeapon"));
        this.cloth = String.valueOf(map.get("Cloth"));
        this.grenade = new Grenade((HashMap<Object, Object>) map.get("Grenade"));
        this.gadgets = (HashMap<String, HashMap<Integer, Integer>>) map.get("Gadgets");
        this.gadgets2 = (HashMap<String, HashMap<Integer, Integer>>) map.get("Gadgets2");
    }

    public MainWeapon getMainWeaponSlot() {
        return this.mainWeapon;
    }

    public SideArms getSideArmsSlot() {
        return this.sidearms;
    }

    public String getMeleeWeaponSlot() {
        return this.meleeWeapon;
    }

    public String getClothSlot() {
        return this.cloth;
    }

    public Grenade getGrenadeSlot() {
        return this.grenade;
    }

    public HashMap<String, HashMap<Integer, Integer>> getGadgetsSlot() {
        return this.gadgets;
    }

    public void setMainWeaponSlot(MainWeapon mainWeapon) {
        this.mainWeapon = mainWeapon;
    }

    public void setSideArmsSlot(SideArms sidearms) {
        this.sidearms = sidearms;
    }

    public void setMeleeWeaponSlot(String meleeWeapon) {
        this.meleeWeapon = meleeWeapon;
    }

    public void setClothSlot(String cloth) {
        this.cloth = cloth;
    }

    public void setGrenadeSlot(Grenade grenade) {
        this.grenade = grenade;
    }

    public void setGadgetsSlot(HashMap<String, HashMap<Integer, Integer>> gadgets) {
        this.gadgets = gadgets;
    }

    public HashMap<Object, Object> SlotToHashMap() {
        HashMap<Object, Object> map = new HashMap<>();
        map.put("MainWeapon", this.mainWeapon.toHashMap());
        map.put("SideArms", this.sidearms.toHashMap());
        map.put("MeleeWeapon", this.meleeWeapon);
        map.put("Cloth", this.cloth);
        map.put("Grenade", this.grenade.toHashMap());
        map.put("Gadgets", this.gadgets);
        map.put("Gadgets2", this.gadgets2);
        return map;
    }

    //Slot{MainWeapon:'',SideArms:'',Melee:'',Gadget:'',Cloth:''}
    @Override
    public String toString() {
        return "Slot{MainWeapon:'" + mainWeapon.toString() + "',SideArms:'" + sidearms.toString() + "'}";
    }

    public void setMainWeaponAmmoSlot(String ammo, int amount) {
        this.mainWeapon.setAmmo(ammo, amount);
    }

    public void setSideArmsAmmoSlot(String ammo, int amount) {
        this.sidearms.setAmmo(ammo, amount);
    }

    public void setMainWeaponAmmoTypeSlot(String ammoType) {
        this.mainWeapon.setAmmoType(ammoType);
    }

    public void setSideArmsAmmoTypeSlot(String ammoType) {
        this.sidearms.setAmmoType(ammoType);
    }

    public void setGadgets2Slot(HashMap<String, HashMap<Integer, Integer>> gadgets2) {
        this.gadgets2 = gadgets2;
    }

    public HashMap<String, HashMap<Integer, Integer>> getGadgets2Slot() {
        return this.gadgets2;
    }
}
